package com.zmn.oms.admin;

import com.google.common.collect.Lists;
import com.zmn.common.utils.date.DateUtil;
import com.zmn.oms.model.entity.track.OrderTrack;
import org.junit.Test;

import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * 类描述：
 *
 * @author lujia
 * @date 2018/12/01 14:56
 */
public class MockData {

    public static void main(String[] args) {
//        Properties properties = new Properties();
//        // 您在控制台创建的 Consumer ID
//        properties.put(PropertyKeyConst.ConsumerId, "CID_DEV_ZMN_OMS");
//        // AccessKey 阿里云身份验证，在阿里云服务器管理控制台创建
//        properties.put(PropertyKeyConst.AccessKey, "LTAIxtAvhqhM2kr4");
//        // SecretKey 阿里云身份验证，在阿里云服务器管理控制台创建
//        properties.put(PropertyKeyConst.SecretKey, "eYTqOlo3SDcBtZrslp7T419SJqhYBW");
//        // 设置 TCP 接入域名，进入 MQ 控制台的消费者管理页面，在左侧操作栏单击获取接入点获取
//        // 此处以公共云生产环境为例
////        properties.put(PropertyKeyConst.ONSAddr,
////                "http://onsaddr-internal.aliyun.com:8080/rocketmq/nsaddr4client-internal");
//        // 集群订阅方式 (默认)
//        // 广播订阅方式
//        // properties.put(PropertyKeyConst.MessageModel, PropertyValueConst.BROADCASTING);
//        Consumer consumer = ONSFactory.createConsumer(properties);
//        consumer.subscribe("dev_zmn_oms", "orderworkchange||orderpartchange", new MessageListener() { //订阅多个 Tag
//            public Action consume(Message message, ConsumeContext context) {
//                System.out.println("Receive: " + message);
//                return Action.CommitMessage;
//            }
//        });
//        //订阅另外一个 Topic
//        consumer.subscribe("dev_zmn_pay", "orderpay", new MessageListener() {
//            public Action consume(Message message, ConsumeContext context) {
//                System.out.println("Receive: " + message);
//                return Action.CommitMessage;
//            }
//        });
//        consumer.start();
//        System.out.println("Consumer Started");
        List<OrderTrack> objects = Lists.newArrayList();
        OrderTrack o1 = new OrderTrack();
        OrderTrack o2 = new OrderTrack();
        OrderTrack o3 = new OrderTrack();
        o1.setCreateTime(DateUtil.parse("2018-02-01 00:00:00"));
        o2.setCreateTime(DateUtil.parse("2018-01-01 00:00:00"));
        o3.setCreateTime(DateUtil.parse("2018-03-01 00:00:00"));
        objects.add(o1);
        objects.add(o2);
        objects.add(o3);
        List<OrderTrack> collect = objects.stream().sorted(Comparator.comparing(OrderTrack::getCreateTime).reversed()).collect(Collectors.toList());
        collect.forEach(e -> {
            System.out.println(DateUtil.toString(e.getCreateTime()));
        });
    }

    @Test
    public void testStreamSort() {
        List<Integer> integers = Lists.newArrayList(1,2,3,4,5,6,7);

        Optional<Integer> maxInt = integers.stream().filter(integer -> integer == 7).max(Comparator.comparing(Integer::intValue, Comparator.naturalOrder()));

        System.out.println(maxInt.isPresent());
        System.out.println(maxInt.get());
        System.out.println(maxInt);

    }
}
